// JavaScript Document
//@require MyClass.js
//@require OpenLayers.js
//clase con funciones para definir un servidor de mapas para OpenLayers.

MyOLServerMap = new MyClass({
	CLASS_NAME: "MyOLServerMap",
	VERSION_NUMBER: "v 1.0.0",

	/**
     * Property: serverCode
     * {String}
	 *   values: GOOGLE | YAHOO | OPENSTREET | BING | WORLDWIND
     */
	 serverCode: 'unknow',

	 /**
     * Property: serverName
     * {String}
	 *   values: GOOGLE | YAHOO | OPENSTREET | BING | WORLDWIND
     */
	 serverName: 'unknow',

	 /**
     * Property: layersNames
     * {Array[String]}
     */
	 layersNames: null,

	 /**
     * Property: projection
     * {String}
     */
	 projection: 'unknow',

	 /**
     * Property: displayProjection
     * {String}
     */
	 displayProjection: 'unknow',

	 /**
     * Property: mapOptions
     * {Object}
     */
	 mapOptions: null,

	 /**
     * Property: layers
     * {Array[OpenLayers.Layer]}
     */
	 layers: null,

	 /**
     * Property: layersTypes
     * {Array[String]}
	 *   	values: STREETS | STREETSRENDER | PHYSICAL | HYBRID | SATELLITE
     */
	 layersTypes: 'unknow',

	 /**
     * Property: actualLayer
     * {OpenLayers.Layer}
     */
	 actualLayer: null,

	 /**
     * Property: actualLayerType
     * {String}
	 * 		values: STREETS | STREETSRENDER | PHYSICAL | HYBRID | SATELLITE
     */
	 actualLayerType: 'unknow',

	 /**
	  *
	  */
	 zoomInitialMap: null,

	/**
     * Method: init
	 * Parameters:
     *   serverCode - {String} values: GOOGLE | YAHOO | OPENSTREET | BING
     */
	init: function(serverCode){
		this.layersTypes = new Array();
		this.layers = new Array();
		this.layersNames = new Array();
		if (serverCode != null){
			serverCode = serverCode.toUpperCase();
			this.serverCode = serverCode;
			if (this.serverCode=="BYKOM")
				this.initServerBykom();
			if (this.serverCode=="GOOGLE")
				this.initServerGoogle();
			if (this.serverCode=="YAHOO")
				this.initServerYahoo()
			if (this.serverCode=="VIRTUALEARTH")
				this.initServerBing();
			if (this.serverCode=="OPENSTREET")
				this.initServerOpenStreet();
			if (this.serverCode=="WORLDWIND")
				this.initServerWorldWind();
		}
	},

	/**
	 * Method: initServerBykom()
	 * 	 Inicializa el servidor de mapas BYKOM
	 */
	initServerBykom: function() {
		//nombre del server
		this.serverName 		= "Bykom";
		//proyecciones
		this.projection 		= new OpenLayers.Projection("EPSG:4326");
		this.displayProjection 	= new OpenLayers.Projection("EPSG:4326");
		var extent 				= new OpenLayers.Bounds(boundsX1,boundsY1,boundsX2,boundsY2);
	    var tempScales 			= AVL_SCALES_LIST;
	    this.zoomInitialMap		= 13;
		//opciones del mapa

		this.mapOptions 		= {
				projection: this.projection,
				displayProjection: this.displayProjection,
		    	maxExtent: extent,
		        scales: tempScales
		};

		//layers
		//BYKOM->STREETS
		var bMap 				= new OpenLayers.Layer.MapGuide( "Bykom Maps Calles", callesUrl, callesParams, callesOptions );
		this.layers.push(bMap);
		this.layersNames.push('Calles');
		this.layersTypes.push('CALLES');
		//set default layers
		this.actualLayer 		= this.layers[0];
		this.actualLayerType 	= this.layersTypes[0];
	},
	/**
     * Method: initServerGoogle()
     * 	 Inicializa el servidor de mapas GOOGLE
     */
	initServerGoogle: function() {
		//nombre del server
		this.serverName = "Google";
		//proyecciones
		this.projection = new OpenLayers.Projection("EPSG:900913");
       	this.displayProjection = new OpenLayers.Projection("EPSG:4326");
       	this.zoomInitialMap		= 13;
		//opciones del mapa
		this.mapOptions = {
                projection: this.projection,
                displayProjection: this.displayProjection,
                units: "km",
                numZoomLevels: 19,
                maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
        	};
		//layers
		//GOOGLE->STREETS
		var gmap = new OpenLayers.Layer.Google("STREETS", {type: G_NORMAL_MAP, 'sphericalMercator': true, MAX_ZOOM_LEVEL:17});
		this.layers.push(gmap);
		this.layersNames.push('Calles');
		this.layersTypes.push('STREETS');
		//GOOGLE-> SATELLITE
        var gsat = new OpenLayers.Layer.Google("SATELLITE", {type: G_SATELLITE_MAP, 'sphericalMercator': true});
		this.layers.push(gsat);
		this.layersNames.push('Satelite');
		this.layersTypes.push('SATELLITE');
		//GOOGLE-> HYBRID
		var ghyb = new OpenLayers.Layer.Google("HYBRID", {type: G_HYBRID_MAP, 'sphericalMercator': true});
		this.layers.push(ghyb);
		this.layersNames.push('Hibrido');
		this.layersTypes.push('HYBRID');
		//GOOGLE->PHYSICAL
		var gphy = new OpenLayers.Layer.Google("PHYSICAL", {type: G_PHYSICAL_MAP, 'sphericalMercator': true});
		this.layers.push(gphy);
		this.layersNames.push('Fisico');
		this.layersTypes.push('PHYSICAL');
		//set default layers
		this.actualLayer = this.layers[0];
		this.actualLayerType = this.layersTypes[0];
	},

	/**
     * Method: initServerYahoo()
     * 	 Inicializa el servidor de mapas YAHOO
     */
	initServerYahoo: function() {
		//nombre del server
		this.serverName = "Yahoo!";
		//proyecciones
		this.projection = new OpenLayers.Projection("EPSG:900913");
       	this.displayProjection = new OpenLayers.Projection("EPSG:4326");
       	this.zoomInitialMap		= 13;
		//opciones del mapa
		this.mapOptions = {
                projection: this.projection,
                displayProjection: this.displayProjection,
                units: "km",
                maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
        	};
		//layers
		//YAHOO->STREETS
		var yahoostreet = new OpenLayers.Layer.Yahoo("STREETS", {'sphericalMercator': true});
		this.layers.push(yahoostreet);
		this.layersNames.push('Calles');
		this.layersTypes.push('STREETS');
		//YAHOO-> SATELLITE
		var yahoosat = new OpenLayers.Layer.Yahoo("SATELLITE", {'type': YAHOO_MAP_SAT, 'sphericalMercator': true});
		this.layers.push(yahoosat);
		this.layersNames.push('Aereo');
		this.layersTypes.push('SATELLITE');
		//YAHOO-> HYBRID
		var yahoohyb = new OpenLayers.Layer.Yahoo("HYBRID", {'type': YAHOO_MAP_HYB, 'sphericalMercator': true});
		this.layers.push(yahoohyb);
		this.layersNames.push('Hibrido');
		this.layersTypes.push('HYBRID');
		//set default layers
		this.actualLayer = this.layers[0];
		this.actualLayerType = this.layersTypes[0];
	},

	/**
     * Method: initServerOpenStreet()
     * 	 Inicializa el servidor de mapas OPENSTREET
     */
	initServerOpenStreet: function() {
		//nombre del server
		this.serverName = "O.Street";
		//proyecciones
		this.projection 		= new OpenLayers.Projection("EPSG:900913");
       	this.displayProjection 	= new OpenLayers.Projection("EPSG:4326");
       	this.zoomInitialMap		= 12;
		//opciones del mapa
		this.mapOptions = {
                projection: this.projection,
                displayProjection: this.displayProjection,
                units: "km",
                maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
        	};
		//layers
		//OPENSTREET->STREETS
		var mapnik = new OpenLayers.Layer.OSM("STREETS");
		this.layers.push(mapnik);
		this.layersNames.push('Calles');
		this.layersTypes.push('STREETS');
		//OPENSTREET->SATELLITE
		var oam = new OpenLayers.Layer.XYZ("SATELLITE","http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/${z}/${x}/${y}.png", {SphericalMercator: true});
		this.layers.push(oam);
		this.layersNames.push('Satelital');
		this.layersTypes.push('SATELLITE');
		//OPENSTREET->STREETSRENDER
		var osmarender = new OpenLayers.Layer.OSM("STREETSRENDER","http://tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png");
		this.layers.push(osmarender);
		this.layersNames.push('Calles D.');
		this.layersTypes.push('STREETSRENDER');
		//set default layers
		this.actualLayer = this.layers[0];
		this.actualLayerType = this.layersTypes[0];

	},

	/**
     * Method: initServerBing()
     * 	 Inicializa el servidor de mapas BING
     */
	initServerBing: function() {
		//nombre del server
		this.serverName = "MS Bing";
		//proyecciones
		this.projection 		= new OpenLayers.Projection("EPSG:900913");
       	this.displayProjection 	= new OpenLayers.Projection("EPSG:4326");
       	this.zoomInitialMap		= 13;
		//opciones del mapa
		this.mapOptions = {
                projection: this.projection,
                displayProjection: this.displayProjection,
                units: "km",
                maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
        	};
		//layers
		//BING->STREETS
		var veroad = new OpenLayers.Layer.VirtualEarth("STREETS",{'type': VEMapStyle.Road, 'sphericalMercator': true});
		this.layers.push(veroad);
		this.layersNames.push('Carreteras');
		this.layersTypes.push('STREETS');
		//BING-> SATELLITE
		var veaer = new OpenLayers.Layer.VirtualEarth("SATELLITE", {'type': VEMapStyle.Aerial, 'sphericalMercator': true});
		this.layers.push(veaer);
		this.layersNames.push('Aereo');
		this.layersTypes.push('SATELLITE');
		//BING-> HYBRID
		var vehyb = new OpenLayers.Layer.VirtualEarth("Virtual Earth Hybrid", {'type': VEMapStyle.Hybrid, 'sphericalMercator': true});
		this.layers.push(vehyb);
		this.layersNames.push('Hibrido');
		this.layersTypes.push('HYBRID');
		//set default layers
		this.actualLayer = this.layers[0];
		this.actualLayerType = this.layersTypes[0];
	},

	/**
     * Method: initServerWorldWind()
     * 	 Inicializa el servidor de mapas WORLDWIND
     */
	initServerWorldWind: function() {
		//nombre del server
		this.serverName = "Nasa WorldWind";
		//proyecciones
		this.projection = new OpenLayers.Projection("EPSG:900913");
       	this.displayProjection = new OpenLayers.Projection("EPSG:4326");
       	this.zoomInitialMap		= 13;
		//opciones del mapa
		this.mapOptions = {
                projection: this.projection,
                displayProjection: this.displayProjection,
                units: "km",
				'maxResolution': 1.6,
				tileSize: new OpenLayers.Size(512, 512),
				numZoomLevels: 21
        	};
		//layers
		//WORLDWIND->SATELLITE
		var wwUrban = ww2 = new OpenLayers.Layer.WorldWind( "SATELLITE",
				"http://worldwind25.arc.nasa.gov/tile/tile.aspx?", .8, 9,
                {T:"104"});

		//var wwUrban = new OpenLayers.Layer.WorldWind( "urban", "http://worldwind25.arc.nasa.gov/tile/tile.aspx?", .8, 9, {T:"104"} );
		this.layers.push(wwUrban);
		this.layersNames.push('Satelite');
		this.layersTypes.push('SATELLITE');

		//set default layers
		this.actualLayer = this.layers[0];
		this.actualLayerType = this.layersTypes[0];
	}

});